package com.example.hfweather.adapter


import android.content.Context
import android.graphics.Color
import android.view.ViewGroup
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.example.hfweather.R
import com.example.hfweather.util.WeatherUtils

import com.qweather.sdk.response.air.v1.AirHourly

class HourAirQualityAdapter  : BaseQuickAdapter<AirHourly, QuickViewHolder>()  {
    override fun onBindViewHolder(
        holder: QuickViewHolder,
        position: Int,
        item: AirHourly?
    ) {
        holder.run {
            //时间点
            setText(R.id.tv_hour, WeatherUtils.isoTo24HourTime(item?.forecastTime.toString()))

            //空气质量数值 23|优
            item?.indexes?.let {
                var airIndex = item.indexes[0]
                airIndex?.let {
                    setText(R.id.tv_hour_air_quality, airIndex.aqiDisplay + " | " + airIndex.category)
                    // 设置文字颜色
                    setTextColor(R.id.tv_hour_air_quality, Color.rgb(
                        airIndex.color.red,
                        airIndex.color.green,
                        airIndex.color.blue
                    ))
                }

                //空气质量等级，如 AQI(CN) 2级
                setText(R.id.tv_hour_air_quality_level, airIndex.name + " " + airIndex.level + "级")
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_hour_air_quality, parent)
    }
}